<?php

// Header
switch ($error['type'])
{
	case 1:
	case 16:	$header = 'PHP Error'; break;
	case 2:
	case 32:	$header = 'PHP Warning'; break;
	case 8:		$header = 'PHP Notice'; break;

	case 256:	$header = 'Aero Error'; break;
	case 512:	$header = 'Aero Warning'; break;
	case 1024:	$header = 'Aero Notice'; break;

	default: 	$header = 'Error';
}


?>
<!DOCTYPE HTML>
<html>
<head>
	<title><?= $header ?></title>
</head>
<?= $View->load('libs/errors/display/stylesheet') ?>
<body>
	<h1><?= $header ?></h1>
	<p>An error encountered in <span class="path"><?= $error['file'] ?></span> on line <span class="line"><?= $error['line'] ?>.</span></p>
	<h2>Error Message</h2>
	<p><?= $error['message'] ?></p>
	
<?php if (!empty($backtrace) && Aero::option('errors.display_backtrace', $is_localhost)): ?>
	<h2>Stack backtrace</h2>
	<ol class="backtrace">
<?php	foreach ($backtrace as $line): ?>
<?php 	if (!is_array($line) || isset($line['function']) && $line['function'] == 'trigger_error') continue; ?>
		<li>
			<span class="path"><?= isset($line['file']) ? $line['file'] .':' : 'PHP inner process:' ?></span>
			<div class="code-block">
<?php
			echo '<span class="line">' . (isset($line['line']) ? $line['line'] . '.' : '') . '</span>';

			$function = isset($line['function']) ? $line['function'] : '';

			$code = '<?php' . (isset($line['class']) ? $line['class'] : '') .
				(isset($line['type']) ? $line['type'] : '') . $function;

			if (isset($line['args']))
			{
				$args = array();

				foreach ($line['args'] as $arg)
				{
					if (is_string($arg))
						$args[] = '"' . $arg . '"';
					else if (is_array($arg))
						$args[] = print_r($arg, true);
					else if (is_bool($arg))
						$args[] = $arg === true ? 'true' : 'false';
					else
						$args[] = $arg;
				}

				$code.= '(' . implode(', ', $args) . '); ?>';
			}

			$code = highlight_string($code,true);
			$code = str_replace(array('&lt;?php','?&gt;'),'',$code);

			echo $code; ?>
		</div></li>
	<?php	endforeach ?>
	</ol>
<?php endif ?>
<?php if (!empty($error_log)): ?>
	<h2>Other errors</h2>
	<ul>
<?php 	foreach ($error_log as $_error): ?>
		<li><?= $_error['message'] ?> in <?= $_error['file'] ?> at line <?= $_error['line'] ?>.</li>
<?php 	endforeach ?>
	</ul>
<?php endif ?>
</body>
</html>